package com.eveinfo.api.accessors;

import java.io.IOException;

import javax.xml.parsers.ParserConfigurationException;

import org.xml.sax.SAXException;

import com.eveinfo.EveInfo;
import com.eveinfo.api.ApiException;
import com.eveinfo.api.NoCacheFoundExecption;
import com.eveinfo.api.utils.skilllist.ApiSkills;
import com.eveinfo.api.utils.skilllist.SkillsParser;
import com.eveinfo.tools.EveInfoPreferences;
import com.eveinfo.tools.Tools;

public class Skills {
	
	private static Skills instance;
	
	private ApiSkills skills;
		
	private Skills()
			throws IOException, SAXException, ParserConfigurationException, ApiException, NoCacheFoundExecption {
		SkillsParser parser = SkillsParser.getInstance();
		final EveInfoPreferences preferences = EveInfo.getPreferences();
		if (preferences.isCacheOnly()) {
			parser.setCacheOnly(true);
			preferences.setEnableCache(true);
		} else {
			parser.setCacheOnly(false);
		}
		if (preferences.isEnableCache()) {
			Tools.setCacheEnable(parser);
		} else {
			Tools.setCacheDisable(parser);
		}
		skills = parser.getSkills();
	}
	
	public static Skills getInstance() throws IOException, SAXException, ParserConfigurationException, ApiException, NoCacheFoundExecption{
		if(instance == null){
			instance = new Skills();
		}
		return instance;
	}

	public ApiSkills getSkills() {
		return skills;
	}
}
